package com.huatai.exchange.receive;

import com.faneui.common.exception.BusinessException;
import com.faneui.common.utils.CloseUtils;
import com.faneui.integration.http.HttpClientUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.huatai.exchange.integration.execd.service.CommandExeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service("fileDataCmdReceiveService")
public class FileDataCmdReceiveServiceImpl extends AbstractFileDataReceiveService {

    @Autowired
    private CommandExeService commandExeService ;

    @Override
    List<String> findAndDownloadFileList(String srcPath, String srcName, String markName, String fileSuffix, String tmpDirPath, Map<String, Object> resvMap) throws BusinessException {
        String fileName = UUID.randomUUID().toString() ;
        OutputStream os = null;
        try{
            os = new FileOutputStream(tmpDirPath + fileName) ;
            // xlsx 加入校验序列
            HttpClientUtils.downLoadFile(srcPath, Maps.newHashMap(), os,fileSuffix);
        }catch (Exception ex) {
            logger.error("",ex);
        }finally {
            CloseUtils.safeClose(os);
        }
        return Lists.newArrayList(fileName);
    }
}
